<?php
class MY_Controller extends CI_Controller
{
	static private $setting;
    function  __construct()
    {
        parent::__construct();
        self::$setting = $this->db->get('setting')->row_array();
    }
    function getSetting($key=''){
    	if($key!=''){
    		return self::$setting[$key];
    	}else{
    		return self::$setting;
    	}
    }
}
 
class AdminBase extends MY_Controller
{
    static private $css_list = [];
    static private $js_list = ['/static/addon/layer-v3.1.1/layer/layer.js'];
    function  __construct()
    {
        parent::__construct();
        if(!$this->session->name){
            redirect('admin/login?redirect='.uri_string(current_url()));
        }else{
            $this->user = $this->db->select('name')->get_where('admin_users',array('username'=>$this->session->name))->row_array();
        }
    }
    function admin_css($ast){
        if(is_array($ast)){
            self::$css_list = array_merge(self::$css_list,$ast);
        }elseif(is_string($ast)){
            array_push(self::$css_list,$ast);
        }
    }
    function admin_js($ast){
        if(is_array($ast)){
            self::$js_list = array_merge(self::$js_list,$ast);
        }elseif(is_string($ast)){
            array_push(self::$js_list,$ast);
        }
    }

    function admin_message($msg,$type){
        self::admin_view('public/message','提示',[
            'message_content' => $msg,
            'message_type' =>$type
        ]);
    }
    function admin_view($html,$title,$data=""){
        $this->db->order_by('order','DESC');
        $menu = $this->db->get('admin_menu')->result_array();
        $this->load->view('admin/public/header',array(
            'top_dir' => $this->router->class,
            'menu' => $menu,
            'title'=>$title,
            'admin_title'=>$this->getSetting('admin_title'),
            'user'=>$this->user,
            'css'=>array_flip(self::$css_list),
            'company_name'=>$this->getSetting('company_name')
        ));
        $this->load->view('admin/'.$html,$data);
        $this->load->view('admin/public/footer',array(
            'js'=>array_flip(self::$js_list)
        ));
    }
}
 
class HomeBase extends MY_Controller
{
    function  __construct()
    {
        parent::__construct();
        
    }

    
}